package com.sea.app.module.process.controller;

import com.sea.app.module.process.domain.service.ActivitiProcessService;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by 31417 on 2017/5/8.
 */
@RestController
@RequestMapping("/process")
public class ActivitiController {

    @Autowired
    ActivitiProcessService activitiProcessService;
    @RequestMapping(value = "speed/{processIncId}")
    public void processDiagram(@PathVariable("processIncId") String processInsId,
                               HttpServletRequest request, HttpServletResponse response) throws IOException {
        ProcessInstance  processInstance = activitiProcessService.findInstance(processInsId);
        String defId = processInstance.getProcessDefinitionId();
        response.sendRedirect(request.getContextPath()
                + String.format("/diagram-viewer/index.html?processDefinitionId=%s&processInstanceId=%s",defId,processInsId));
    }
}
